package aop;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

public class LogAroundAdvice implements MethodInterceptor{

	//MethodInvocation相当于Method的包装类
	public Object invoke(MethodInvocation methodInvocation) throws Throwable {
		MyLogger logger = new MyLogger();
		
		try{
			logger.log("before: "+methodInvocation.getMethod().getName()+
								",    args"+methodInvocation.getArguments());
			
			//须执行目标方法！
			Object result = methodInvocation.proceed();
			
			logger.log("after: "+methodInvocation.getMethod().getName());
			
			//注意返回目标方法的返回值
			return result;
		}
		catch(Exception e){
			logger.log("Exception: "+e.getMessage());
			throw e;
		}
		
	}

}
